package com.example.testsinglety.inventory;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(
        topic = "ORDER_TOPIC",
        consumerGroup = "inventory-group"
)
public class InventoryListener implements RocketMQListener<String> {
    @Autowired
    private InventoryService inventoryService;

    @Override
    public void onMessage(String orderId) {
        // 异步处理库存
        inventoryService.reduceStock(orderId);
    }

}
